package com.huike.web.controller.system;

import com.huike.clues.domain.SysNotice;
import com.huike.clues.domain.dto.SysNoticeDTO;
import com.huike.clues.service.ISysNoticeService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.SecurityUtils;
import com.mysql.cj.protocol.x.Notice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("通知公告")
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService noticeService;

    @GetMapping("/pagelist/{status}")
    @ApiOperation("分页查询")
    public AjaxResult<List<SysNoticeDTO>> noticeList(@PathVariable String status) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(SecurityUtils.getUserId(), status);
        return AjaxResult.success(list);
    }

    @GetMapping("/list/{status}")
    @ApiOperation("下拉列表")
    public AjaxResult<List<SysNoticeDTO>> list(@PathVariable String status) {
        List<SysNotice> list = noticeService.selectNoticeList(SecurityUtils.getUserId(), status);
        return AjaxResult.success(list);
    }

    @GetMapping("/{noticeId}")
    @ApiOperation("公告详情")
    public AjaxResult gitInfo(@PathVariable Long noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }

    @PutMapping("/{noticeId}")
    @ApiOperation("已读变未读")
    public AjaxResult edit(@PathVariable Long noticeId){
        return toAjax(noticeService.updateNoticeRead(noticeId));
    }
}
